{% extends "layouts" ~ DIR ~ "default.twig" %}

{% block title %}{{ "Manage Uploads" | translate }}{% endblock %}

{% block content %}
<form class="filters" action="{{ url('manage_uploads') }}" method="post" accept-charset="UTF-8" role="search">
<fieldset role="presentation">
<label for="search">{{ "Search&hellip;" | translate }}</label>
<input class="text filter_text" type="text" name="search" value="{{ GET.search is defined ? GET.search | fix(true, true) : '' }}" id="search">
<button type="submit">{{ "Search" | translate }}</button>
{% if visitor.group.can("import_content") %}
<a href="{{ url('import') }}" class="button yay">
{{ icon_svg("add.svg") }}{{ "Add Files" | translate }}
</a>
{% endif %}
</fieldset>
</form>
<h2>{{ GET.search is defined ? "Search Results" | translate : "Uploads" | translate }}</h2>
<table class="interactive{{ uploads.paginated is empty ? ' empty' : '' }}">
<thead>
<tr class="head">
<th class="uploads_name filename main">{{ "Name" | translate }}</th>
<th class="uploads_modified date">{{ "Last Modified" | translate }}</th>
<th class="uploads_size value">{{ "Size" | translate }}</th>
<th class="uploads_type value">{{ "Type" | translate }}</th>
{{ trigger.call("manage_uploads_column_header") }}
<th class="controls" colspan="3">{{ "Controls" | translate }}</th>
</tr>
</thead>
<tbody>
{% for upload in uploads.paginated %}
<tr id="uploads_{{ loop.index }}" class="uploads">
<td class="uploads_name filename main">
{% if ["jpg", "jpeg", "png", "webp", "gif"] | contains(upload.type) %}
{{ upload.name | thumbnail("", false, ["max_width=70", "quality=60", "square=1"], "70px") }}
{% elseif ["avif", "tif", "tiff", "heif", "bmp"] | contains(upload.type) %}
{{ icon_svg("image.svg", false, "placeholder") }}
{% elseif ["mp3", "m4a", "oga", "ogg", "mka", "flac", "wav", "aiff"] | contains(upload.type) %}
{{ icon_svg("audio.svg", false, "placeholder") }}
{% elseif ["mpg", "mpeg", "mp2", "mp4", "m4v", "ogv", "mkv",  "mov", "avi", "webm", "3gp", "ts"] | contains(upload.type) %}
{{ icon_svg("video.svg", false, "placeholder") }}
{% elseif ["zip", "tar", "rar", "gz", "bz2", "7z", "dmg", "cab", "iso", "udf"] | contains(upload.type) %}
{{ icon_svg("archive.svg", false, "placeholder") }}
{% else %}
{{ icon_svg("file.svg", false, "placeholder") }}
{% endif %}
<a target="_blank" href="{{ upload.name | uploaded }}">{{ upload.name | fix(false, true) }}</a>
</td>
<td class="uploads_modified value">
{{ upload.modified | time("Y-m-d H:i:s") }}
</td>
<td class="uploads_size value">
{{ upload.size | filesizeformat }}
</td>
<td class="uploads_type value">
{{ upload.type | upper }}
</td>
{{ trigger.call("manage_uploads_column", upload) }}
<td class="controls">
{%- if visitor.group.can("view_upload") -%}
<a class="emblem" href="{{ upload.name | download }}">
{{ icon_svg("download.svg", "Download" | translate) }}
</a>
{%- else -%}
{{ icon_svg("forbidden.svg", false, "emblem forbidden") }}
{%- endif -%}
</td>
<td class="controls">
{%- if visitor.group.can("edit_upload") -%}
<a class="upload_edit_link edit_link emblem" href="{{ url('edit_upload/file/' ~ (upload.name | url_encode)) }}">
{{ icon_svg("edit.svg", "Edit" | translate) }}
</a>
{%- else -%}
{{ icon_svg("forbidden.svg", false, "emblem forbidden") }}
{%- endif -%}
</td>
<td class="controls">
{%- if visitor.group.can("delete_upload") -%}
<a class="upload_delete_link delete_link emblem" href="{{ url('delete_upload/file/' ~ (upload.name | url_encode)) }}">
{{ icon_svg("delete.svg", "Delete" | translate) }}
</a>
{%- else -%}
{{ icon_svg("forbidden.svg", false, "emblem forbidden") }}
{%- endif -%}
</td>
</tr>
{% else %}
<tr>
<td class="placeholder">
{{ icon_svg("failure.svg", false, "emblem") }}
{{ "No results" | translate }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="controls">
<form action="{{ self_url() }}" method="post" accept-charset="UTF-8">
<label for="uploads_sort">{{ "Sort results by:" | translate }}</label>
<select name="sort" id="uploads_sort">
{% for value, label in uploads_columns %}
<option value="{{ value }}"{{ value | selected(uploads_sort) }}>
{{ label }}
</option>
{% endfor %}
</select>
<button type="submit">{{ "Sort Results" | translate }}</button>
</form>
</div>
{% if uploads.paginated is not empty and uploads.pages > 1 %}
<div class="pagination">
<span class="pages">{{ "Page %d of %s" | translate | format(uploads.page, uploads.final_link(uploads.pages)) }}</span>
{{ uploads.prev_link }}
{{ uploads.next_link }}
</div>
{% endif %}
{% endblock %}
